
/**
 * Created by Administrator on 2022/9/1.
 */
/*class Person implements Comparable {
    public String name;
    public int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name=" + name +
                ", age=" + age +
                '}';
    }


    @Override
    public int compareTo(Object o) {
        Person a = (Person) o;
        return this.name.compareTo(a.name);
        //return this.age - a.age;
    }
}
public class Test6 {
    public static void main(String[] args) {
        Person[] person = new Person[3];
        person[0] = new Person("zhangsan",9);
        person[1] = new Person("lisi",11);
        person[2] = new Person("wangwu",10);
        Arrays.sort(person);
        for (Person x:person) {
            System.out.println(x);
        }
    }
}*/


class Person implements Cloneable {
    public String name;
    Person2 person2 = new Person2(12);

    public Person(String name) {
        this.name = name;
    }

    /*@Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }*/

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp =(Person) super.clone();
        tmp.person2 = new Person2(9);
        return tmp;
    }
}
class Person2 {
    public int age;

    public Person2(int age) {
        this.age = age;
    }
}
public class Test6 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person("李四");
        Person person2 = (Person) person1.clone();
        System.out.println(person2.name);
        System.out.println(person2.person2.age);
        System.out.println(person1.person2.age);

    }
}